package com.huike.web.controller.clues;

import com.huike.clues.domain.TbCourse;
import com.huike.clues.domain.dto.TbCourseDTO;
import com.huike.clues.domain.dto.mydto.ActivityQueryDTO;
import com.huike.clues.domain.dto.mydto.CourseQueryDTO;
import com.huike.clues.service.TbCourseService;
import com.huike.common.annotation.Log;
import com.huike.common.annotation.RepeatSubmit;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.enums.BusinessType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 课程管理Controller
 *
 * @date 2023-04-01
 */
@Slf4j
@RestController
@RequestMapping("/clues/course")
public class TbCourseController extends BaseController {

    @Autowired
    private TbCourseService tbCourseService;

    /**
     * 新增课程管理
     *
     * @param tbCourseDTO
     * @return
     */
    @Log(title = "课程管理", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping
    public AjaxResult addTbCourse(@RequestBody TbCourseDTO tbCourseDTO) {
        log.info("新增课程管理:{}", tbCourseDTO);
        return toAjax(tbCourseService.addTbCourse(tbCourseDTO));
    }


    /**
     * 修改课程管理
     */
    @Log(title = "课程管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult updateTbCourse(@RequestBody TbCourseDTO tbCourseDTO) {
        log.info("修改课程管理:{}", tbCourseDTO);
        return toAjax(tbCourseService.updateTbCourse(tbCourseDTO));
    }


    /**
     * 分页查询课程管理信息
     */
    @GetMapping("/list")
    public TableDataInfo list(CourseQueryDTO courseQueryDTO ) {
        startPage();
        List<TbCourse> list = tbCourseService.selectTbCourseList(courseQueryDTO);
        return getDataTable(list);
    }

    /**
     * 课程下拉列表
     *
     * @return
     */
    @GetMapping("/listselect")
    public AjaxResult selectTbCourseSubject(String subject) {
        List<TbCourse> tbCourse = tbCourseService.selectTbCourseSubject(subject);
        return AjaxResult.success(tbCourse);
    }


    /**
     * 删除课程管理
     *
     * @param ids
     * @return
     */
    @Log(title = "课程管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult delectTbCourse(@PathVariable Long[] ids) {
        return toAjax(tbCourseService.delectTbCourse(ids));
    }

    /**
     * 查询课程管理详细信息
     *
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult selectTbCourse(@PathVariable Long id) {
        TbCourse tbCourse = tbCourseService.selectTbCourse(id);
        return AjaxResult.success(tbCourse);
    }
}
